<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="职位" prop="UserTypeName">
        <el-input v-model="ruleForm.UserTypeName"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即添加</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import axios from "@/util/axios.js";
export default {
  props: { id: Object },
  data() {
    return {
      ruleForm: {
        UserTypeName: "",
        
      },
     
      rules: {
        UserTypeName: [
          { required: true, message: "请输入职位", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("api/UserTypes/Insert", this.ruleForm).then((res) => {
            this.$emit("add-ok");
            if (res.data.Code == 0) {
              this.$emit("add-ok");
            } else {
              this.$message("职位信息重复");
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getTable(){
        axios.get("api/UserTypes/GetUserTypeById?usertypeid="+this.id).then((res)=>{
            this.ruleForm=res.data;
        })
    }
  },
  created() {
    this.ruleForm.id=this.id;
    this.getTable();
  },
  watch:{
    id(val)
    {
      this.ruleForm.id=val;
      this.getTable();
    }
  }
};
</script>
<style>
</style>